import {
  createRouter,
  createWebHistory
} from 'vue-router'
import {
  setupRouterGuards
} from './guards'
import freshRoutes from './fresh'
const adminRoutes = [{
    path: '/admin/login',
    component: () => import('@/views/adminLogin/LoginPage.vue')
  },
  {
    path: '/admin',
    component: () => import('@/views/adminLayout/LayoutContainer.vue'),
    // meta意思是
    meta: {
      requireAdmin: true
    },
    redirect: '/admin/user/profile',
    children: [{
        path: '/admin/user/profile',
        meta: {
          requireAdmin: true
        },
        component: () => import('@/views/adminUser/UserProfile.vue')
      },
      {
        path: '/admin/user/avatar',
        meta: {
          requireAdmin: true
        },
        component: () => import('@/views/adminUser/UserAvatar.vue')
      },
      {
        path: '/admin/user/password',
        meta: {
          requireAdmin: true
        },
        component: () => import('@/views/adminUser/UserPassword.vue')
      },
      {
        path: '/admin/logs',
        meta: {
          requireAdmin: true
        },
        component: () => import('@/views/adminLogs/LogsPage.vue')
      }
    ]
  }
]
const router = createRouter({
  history: createWebHistory(
    import.meta.env.BASE_URL),
  routes: [{
      path: '/login',
      component: () => import('@/views/login/LoginPage.vue')
    },
    {
      path: '/register',
      component: () => import('@/views/login/RegisterPage.vue')
    },
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      component: () => import('@/views/home/indexPage.vue')
      // 首页不需要登录即可访问
    },
    // {
    //   path: '/fresh',
    //   component: () => import('@/views/fresh/indexPage.vue'),
    //   meta: {
    //     requireAuth: true
    //   }
    // },
    ...freshRoutes,
    {
      path: '/kitchen',
      component: () => import('@/views/kitchen/indexPage.vue'),
      meta: {
        requireAuth: true
      }
    },
    {
      path: '/dining',
      component: () => import('@/views/dining/indexPage.vue'),
      meta: {
        requireAuth: true
      }
    },
    {
      path: '/essential',
      component: () => import('@/views/essential/indexPage.vue'),
      meta: {
        requireAuth: true
      }
    },
    {
      path: '/clean',
      component: () => import('@/views/clean/indexPage.vue'),
      meta: {
        requireAuth: true
      }
    },
    { path: '/baby', component: () => import('@/views/baby/indexPage.vue'), meta: { requireAuth: true } },
    { path: '/clothing', component: () => import('@/views/clothing/indexPage.vue'), meta: { requireAuth: true } },
    { path: '/search', name: 'searchResult', component: () => import('../views/SearchResult.vue') },
    { path: '/goods/:id', name: 'GoodsDetail', component: () => import('@/views/goods/indexPage.vue'), props: true },
    ...adminRoutes,
  ]
})

// 启用路由守卫
setupRouterGuards(router)

export default router
